ModEditor.EventManager = {}
local Hooks = {}

function ModEditor.EventManager.AddHook(name,f)
	if Hooks[name] == nil then
		Hooks[name] = {}
	end
	table.insert(Hooks[name],1,f)
	return true
end

function ModEditor.EventManager.CallEvent(name,...)
	if Hooks[name] == nil then
		ModEditor.Log("There is no function to process hook "..name,WARNING)
		return
	end
	local processed = 0
	for i = 1,#Hooks[name] do
		local result,retvals = ModEditor.SafeCall(Hooks[name][i],"Can't execute hook \""..name.."\":",...)
		if result then
			if retvals then
				processed = 1
				break
			end
		else
		end
	end
	return processed
end

local function MakeHook(tbname,name)
	add_hook(tbname,"modeditorhooks",function(...)
		ModEditor.EventManager.CallEvent(name,...)
	end)
end

MakeHook("draw2d","Draw2D")
MakeHook("draw3d","Draw3D")
MakeHook("mouse_button_down","MouseDown")
MakeHook("mouse_button_up","MouseUp")
MakeHook("mouse_move","MouseMove")
MakeHook("key_down","KeyDown")
MakeHook("key_up","KeyUp")
